<?php
// 本类由系统自动生成，仅供测试用途
class SearchAction extends Action {
     public function index(){
		R('Index/indexpic');
		$this->search();
		$this->resentsch();
        $this->display();
    }

	public function result(){
		R('Index/indexpic');
		R('Intro/gangwei');
		$this->resentsch();
        $this->display();
	}

	private function search(){
		$key=$_GET['sch'];
		if($key!=null){
			$this->assign('sch',$key);
			$article=M('article');
			import("ORG.Util.Page");//导入分页类
			$cond['title']=array('like','%'.$key.'%');
			$cond['type']=array('not in','首页顶图,首页图片切换,信息公示图片,业务介绍图片');
			$index=$article->where($cond)->count();
			if($index!=0)//有结果
			{
				$this->addrsch($key);
				$Page = new Page($index,12);//实例化分页类传入总记录数和每页显示的记录数
				$show = $Page->show();//分页显示输出
				$list = $article->where($cond)->order('istop DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
				for($i=0;$i<count($list);$i++){
					$list[$i]['pubtime'] = 	date("Y-m-d",$list[$i]['pubtime']);
				}
				$this->assign('list',$list);
				$this->assign('page',$show);//赋值分页输出
			}
			else
			{
				$this->hotsearch();
			}
		}else{
			$this->hotsearch();
		}
	}

	private function hotsearch(){
		$empty="对不起，没有搜到您想要的结果,我们接下来为您提供了大厅业务的详细指南：";
		$article=M('article');
		import("ORG.Util.Page");//导入分页类
		$cond['type']='岗位介绍';
		$list=$article->where($cond)->limit('0,12')->select();
		$this->assign('empty',$empty);
		$this->assign('list',$list);
	}
	//显示最近搜索
	public function resentsch(){
		$model=M('search');
		$list=$model->order('time DESC')->limit('0,6')->select();
		$this->assign('rsch',$list);
	}
	//添加最近搜索
	public function addrsch($key){
		$model = M('search');
        //保存当前数据对象
		$data=array(
			'key'=>$key,
			'time'=>time()
			);
		$cond['key']=$key;
		$list=$model->where($cond)->select();
		if($list!=null)
		{
			$model->where($cond)->setField(array('time'=>time()));
			$model->where($cond)->setInc('freq');
		}
		else
		{
			$data['id']=$_POST['id'];
			$list = $model->add($data);
		}
	}
}